package com.xqb.modules.controller.course;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.LesCourseSubject;
import com.xqb.modules.service.ILesCourseSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程题目关系列Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/course/courseSubject")
public class LesCourseSubjectController extends BaseController
{
    @Autowired
    private ILesCourseSubjectService lesCourseSubjectService;

    /**
     * 查询课程题目关系列列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(LesCourseSubject lesCourseSubject)
    {
        startPage();
        List<LesCourseSubject> list = lesCourseSubjectService.selectLesCourseSubjectList(lesCourseSubject);
        return getDataTable(list);
    }

    /**
     * 导出课程题目关系列列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject:export')")
    @Log(title = "课程题目关系列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesCourseSubject lesCourseSubject)
    {
        List<LesCourseSubject> list = lesCourseSubjectService.selectLesCourseSubjectList(lesCourseSubject);
        ExcelUtil<LesCourseSubject> util = new ExcelUtil<LesCourseSubject>(LesCourseSubject.class);
        util.exportExcel(response, list, "课程题目关系列数据");
    }

    /**
     * 获取课程题目关系列详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lesCourseSubjectService.selectLesCourseSubjectById(id));
    }

    /**
     * 新增课程题目关系列
     */
    @PreAuthorize("@ss.hasPermi('course:subject:add')")
    @Log(title = "课程题目关系列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LesCourseSubject lesCourseSubject)
    {
        return toAjax(lesCourseSubjectService.insertLesCourseSubject(lesCourseSubject));
    }

    /**
     * 修改课程题目关系列
     */
    @PreAuthorize("@ss.hasPermi('course:subject:edit')")
    @Log(title = "课程题目关系列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesCourseSubject lesCourseSubject)
    {
        return toAjax(lesCourseSubjectService.updateLesCourseSubject(lesCourseSubject));
    }

    /**
     * 删除课程题目关系列
     */
    @PreAuthorize("@ss.hasPermi('course:subject:remove')")
    @Log(title = "课程题目关系列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lesCourseSubjectService.deleteLesCourseSubjectByIds(ids));
    }
}
